//
// Created by root on 24-3-13.
//
#pragma once

#include "pipeline.hpp"
#include "pipeline_group.hpp"
#include "physical_operator.hpp"
#include "physical_operator_type.hpp"
#include "planner.hpp"

namespace DaseX
{

    class PhysicalOperator;
    class ExecuteContext;

    class Pipe {
    public:

        explicit Pipe(int parallel_num) : parallel_num_(parallel_num){}

        std::shared_ptr<PhysicalOperator>  root;

        std::shared_ptr<PhysicalOperator>  child;

        Pipe *next;

        std::vector<std::shared_ptr<PhysicalOperator>>  parents;

        std::vector<std::shared_ptr<PhysicalOperator>>  physical_ops;

        std::vector<PhysicalOperatorType>  resource_type_;

        std::vector<PhysicalOperatorType>  sink_type_;

        int parallel_num_ = 72;

        // return std::shared_ptr<const Pipe>
        auto BuildPipe(const AbstractPlanNodeRef& plan) -> std::vector<std::shared_ptr<PhysicalOperator>> ;

        auto BuildPipelineGroup() -> int;

        std::vector<int> resource_idxs;

        std::vector<int> sink_idxs;

        // ============= some test function =============
        void GetResouceIdx() {
            printf("Resources: ");
            for(auto idx : resource_idxs) {
                printf("%d ",idx);
            }
            printf("\n");
        }

        void GetResouceType() {
            printf("Resource: ");
            for(auto idx : resource_type_) {
                printf("%d ",idx);
            }
            printf("\n");
        }

        void GetSinkIdx() {
            printf("Sinks: ");
            for(auto idx : sink_idxs) {
                printf("%d ",idx);
            }
            printf("\n");
        }

        void GetSinkType() {
            printf("Sink: ");
            for(auto idx : sink_type_) {
                printf("%d ",idx);
            }
            printf("\n");
        }

    };


}

